<!--
* description: 区县管理-新增、修改弹窗
* author: yinxy
* createdDate: 2019-08-0
-->
<template>
  <section class="countryManageEdit">
    <el-dialog
      :key="popupsTableKey"
      v-dialogDrag
      :close-on-click-modal="false"
      :title="textMap[popupsState]"
      :append-to-body="true"
      :visible.sync="curPopupsVisible"
      width="1000px"
      @close="sendCode"
    >
      <dialogHeader
        slot="title"
        :title="textMap[popupsState]"
        :style-type="$store.state.app.dialogType"
      />
      <div class="filter-container filter-params">
        <el-row
          ref="vailComponentList"
          :gutter="26"
        >
          <component
            :is="comp.component"
            v-for="comp in tableComponents.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire+ comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :code="formField[comp.codeField]"
            :text="formField[comp.textField]"
            :disabled="comp.disabled"
            :is-require="comp.isRequire"
            :is-mul="comp.isMul"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :parent-fileds="comp.parentFileds"
            :date-options-type="comp.dateOptionsType"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
          />
        </el-row>
      </div>
      <div
        slot="footer"
        class="dialog-footer"
      >
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          :icon="comp.icon"
          @click="comp.clickEvent"
        >{{ comp.text }}</el-button>
      </div>
    </el-dialog>
  </section>
</template>
<script>
import { formMixins } from '@/components/mixins/formMixins'
import { valueObjectMixins } from '@/components/mixins/valueObjectMixins'
import { orgApis } from '@/api/apiList/org'
export default {
  components: {
    dialogHeader: () => import('@/components/dialogHeader') // 弹窗标题
  },
  // 组件混入对象
  mixins: [formMixins, valueObjectMixins],
  data() {
    return {
      // 保存API配置对象
      apiConfig: orgApis.mdmOrgCommutiySave,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          icon: 'iconfont  icon-preservation',
          clickEvent: () => this.save(),
          text: this.$t('sys.button.save') // 保存
        },
        {
          compKey: 'btnKey2',
          type: '',
          size: 'small',
          icon: 'iconfont  icon-reset',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset') // 重置
        },
        {
          compKey: 'btnKey3',
          type: '',
          size: 'small',
          icon: 'iconfont  icon-cancel',
          clickEvent: () => this.sendCode(),
          text: '取消' // 重置
        }
      ],
      // 动态组件-查询条件
      tableComponents: [],
      // 静态组件-查询条件
      staticTableComponents: [
        {
          compKey: 'compKey2',
          isMul: false,
          labelName: this.$t('org.label.provinceName'), // 所属省份
          isRequire: true,
          codeField: 'provinceId',
          disabled: true,
          component: () => import('@/components/org/ProvinceQuery'),
          type: 'dropdownList',
          isMust: true
        },
        {
          compKey: 'compKey3',
          labelName: this.$t('org.label.cityName'), // 所属城市
          isRequire: true,
          parentFileds: 'provinceId',
          codeField: 'cityId',
          disabled: true,
          component: () => import('@/components/org/CitySelect'),
          type: 'dropdownList',
          isMust: true
        },
        {
          compKey: 'compKey1',
          labelName: this.$t('org.label.countyCode'), // 区县编码
          isRequire: true,
          codeField: 'countyCode',
          disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true
        },
        {
          compKey: 'compKey5',
          labelName: this.$t('org.label.countyName'), // 区县名称
          isRequire: true,
          codeField: 'countyName',
          disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true
        },
        {
          compKey: 'compKey4',
          labelName: this.$t('org.label.isEnableCn'), // 启用状态
          isRequire: true,
          isMul: false,
          codeField: 'isEnable',
          component: () => import('@/components/org/isEnable/isEnableOne'),
          type: 'dropdownList',
          isMust: true
        }
      ],
      // 标题
      textMap: {
        edit: this.$t('org.label.editCounty'), // 修改区县信息
        add: this.$t('org.label.addCounty') // 新增区县信息
      },
      // 表单数据（无需赋值，由混入对象赋值）
      formField: {
        countyName: '',
        countyCode: '',
        updateControlId: '',
        provinceId: '',
        cityId: '',
        countyId: '',
        isEnable: '',
        cityCode: '',
        countyId: ''
      }
    }
  },
  methods: {
    save() {
      const that = this
      this.$utils.validataMoth(this, 'validpopup')
      if (this.valid) {
        const obj = {
          countyCode: this.formField.countyCode,
          // provinceId: this.formField["mdmOrgCityExt.mdmOrgProvinceExt.provinceId"],
          cityId: this.formField.cityId,
          countyName: this.formField.countyName,
          updateControlId: this.formField.updateControlId,
          isEnable: this.formField.isEnable,
          countyId: this.formField.countyId
        }
        this.isMul = false
        // 保存表单
        this.saveForm(obj)
      }
    }
  }
}
</script>
